package Threadpack;
import java.lang.*;
class A extends Thread
{
	public void run()
	{
		for (int i=1;i<=5;i++)
		{
			
			if(i==2)
			{
				System.out.println("Releasing control through yeild I:"+i);
				yield();
			}
			System.out.println("From Thread A I:"+i);
		}
		System.out.println("Exit From Thread A ");
	}
}

class B extends Thread
{
	public void run()
	{
		for (int j=1;j<=5;j++)
		{
			
			if(j==2)
			{
				
				
				try
				{
					System.out.println("Thread B going for sleep J:"+j);
					sleep(5000);
					
				}
				catch(Exception e)
				{
				System.out.println("Error:");
				}
			}
	
			System.out.println("From Thread B J:"+j);
		    
		}
		System.out.println("Exit From Thread B ");
	}
}

class C extends Thread
{
	public void run()
	{
		for (int k=1;k<=5;k++)
		{
			System.out.println("From Thread C K:"+k);
			if(k==3)
			{
				System.out.println("Thread C going for suspnd k:"+k);
				try
				{
				  suspend();
				}
				catch(Exception e)
				{
					System.out.println("Error");
				}
				

			}
			System.out.println("From Thread C K:"+k);
		}
		System.out.println("Exit From Thread C ");
	}
}

class D extends Thread
{
	public void run()
	{
		for (int n=1;n<=5;n++)
		{
           System.out.println("From Thread D N:"+n);
			if(n==2)
			{
				System.out.println("Thread D is going to Dead n:"+n);
				stop();
				
			}
			
		}
		System.out.println("Exit From Thread D");
	}
}

public class Thread2 
{
	public static void main(String[] args)
    {
       A trd1 = new A();
       B trd2 = new B();
       C trd3 = new C();
       D trd4 = new D();
       
       System.out.println("Starting thread A");
       trd1.start();
       System.out.println("Starting thread B");
       trd2.start();
       System.out.println("Starting thread C");
       trd3.start();
       System.out.println("Starting thread D");
       trd4.start();
       System.out.println("Exit from Main");
       trd3.resume();
    }
}
